﻿using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security;
using System.Text;

namespace PermissionReporting.Helpers
{
    public static class CredentialHelper
    {
        public static ICredentials GetCredentials(string UserName, string Password)
        {
            SecureString securePassword = new System.Security.SecureString();
            foreach (char c in Password)
            {
                securePassword.AppendChar(c);
            }

            //// Needs to set new credentials to read from source
            if (UserName.Contains("\\"))
            {
               return new NetworkCredential(UserName, securePassword);
            }
            else
            {
                return new SharePointOnlineCredentials(UserName, securePassword);
            }
        }

        public static ICredentials GetCredentials(SPCredentials CurrentUserCredentials)
        {
            return GetCredentials(CurrentUserCredentials.UserName, CurrentUserCredentials.Password);
        }
    }
}
